package com.steak.concurrent.CompletableFuture.api.call;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * @author 刘牌
 * @Title:
 * @date 2022-04-2314:01
 */
public class Final {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> completedFuture = CompletableFuture.supplyAsync(() -> {
            int i = 1 / 0;
            return 100;
        });

        CompletableFuture<Integer> completeAsync = CompletableFuture.supplyAsync(() -> 100)
                .thenCombineAsync(completedFuture, (s, th) -> {
                    System.out.println("start ");
                    return s;
                }).whenCompleteAsync((s, th) -> {
                    System.out.println("finally do it " + s);
                });
        System.out.println(completeAsync.get());
    }
}
